//
//  JQFYTickrtInfo_GroupListCell.m
//  JQFY
//
//  Created by apple on 2017/10/13.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYTickrtInfo_GroupListCell.h"

@interface JQFYTickrtInfo_GroupListCell ()
@property (nonatomic ,strong) UIImageView *bgView;
@property (nonatomic ,strong) UILabel *groupName;
@property (nonatomic ,strong) UILabel *groupCount;
@property (nonatomic ,strong) UIImageView *iconImg;
@property (nonatomic ,strong) UILabel *avtivityLabel;
@end
@implementation JQFYTickrtInfo_GroupListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}
//自定义布局
-(void) setupUI{
    
    self.backgroundColor = [UIColor clearColor];
    
    _bgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView);
        make.bottom.mas_equalTo(self.contentView).mas_offset(-5 *SCAL);
        make.leading.mas_equalTo(self.contentView).mas_offset(-5 *SCAL);
        make.trailing.mas_equalTo(self.contentView).mas_offset(5 *SCAL);
    }];
    UIImage *bgimg = [UIImage imageNamed:@"cellBg"];
    _bgView.layer.contents = (id)bgimg.CGImage;
    
    //lineView
    UIView *lineView = [[UIImageView alloc] init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [_bgView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(_bgView).mas_offset(7 *SCAL);
        make.trailing.mas_equalTo(_bgView).mas_offset(-7 *SCAL);
        make.bottom.mas_equalTo(_bgView).offset(-1*SCAL);
        make.height.mas_offset(1 *SCAL);
    }];
    //布局背景视图
    UIImageView *contantView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBg-1"]];
    [_bgView addSubview:contantView];
    [contantView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_bgView);
        make.leading.mas_equalTo(_bgView).mas_offset(5 *SCAL);
        make.trailing.mas_equalTo(_bgView).mas_offset(-5 *SCAL);
        make.bottom.mas_equalTo(_bgView).mas_offset(-9 *SCAL);
    }];
    //icon图标
//    _iconImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"group_iconImg"]];
    _iconImg = [[UIImageView alloc]init];
    [contantView addSubview:_iconImg];
    [_iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(contantView);
        make.width.height.mas_offset(60 *SCAL);
        make.leading.mas_equalTo(contantView).mas_offset(20 *SCAL);
    }];
    _iconImg.layer.cornerRadius = 30 *SCAL;
    _iconImg.layer.masksToBounds = YES;
    //groupName
    _groupName = [[UILabel alloc] init];
    [contantView addSubview:_groupName];
    [_groupName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(_iconImg.mas_trailing).mas_offset(20 *SCAL);
        make.top.mas_equalTo(contantView).mas_offset(10 *SCAL);
    }];
    _groupName.text = @"UNINHIBITED";
    _groupName.textColor = RGBCOLOR(137, 0, 234);
    _groupName.font = [UIFont fontWithName:@"Arial-BoldMT" size:18 *SCAL];
    
    //活动名称
    _avtivityLabel = [[UILabel alloc] init];
    [contantView addSubview:_avtivityLabel];
    [_avtivityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(_iconImg.mas_trailing).mas_offset(20 *SCAL);
        make.width.mas_offset(150 *SCAL);
        make.top.mas_equalTo(_groupName.mas_bottom).mas_offset(1 *SCAL);
    }];

    _avtivityLabel.textColor = [UIColor lightGrayColor];
    _avtivityLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:10 *SCAL];
    
    //人数icon
    UIImageView *peopleicon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"group_iconPeople"]];
    [contantView addSubview:peopleicon];
    [peopleicon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_avtivityLabel.mas_bottom).offset(4 *SCAL);
        make.width.mas_offset(16 *SCAL);
        make.height.mas_offset(9 *SCAL);
        make.leading.mas_equalTo(_iconImg.mas_trailing).mas_offset(20 *SCAL);
    }];
    //群主icon
//    UIImageView *groupOwner = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"group_iconOwner"]];
//    [contantView addSubview:groupOwner];
//    [groupOwner mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(avtivityLabel.mas_bottom).offset(4 *SCAL);
//        make.width.mas_offset(16 *SCAL);
//        make.height.mas_offset(9 *SCAL);
//        make.leading.mas_equalTo(peopleicon.mas_trailing).mas_offset(35 *SCAL);
//    }];
    //群人数
    _groupCount = [[UILabel alloc] init];
    [contantView addSubview:_groupCount];
    [_groupCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(peopleicon.mas_trailing).mas_offset(2 *SCAL);
        make.bottom.mas_equalTo(peopleicon);
    }];
    _groupCount.text = @"200";
    _groupCount.textColor = [UIColor lightGrayColor];
    _groupCount.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
    //群主名字
//    UILabel *headerName = [[UILabel alloc] init];
//    [contantView addSubview:headerName];
//    [headerName mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(groupOwner.mas_trailing).mas_offset(2 *SCAL);
//        make.bottom.mas_equalTo(groupOwner);
//    }];
//    headerName.text = @"UNINHIBITED";
//    headerName.textColor = [UIColor grayColor];
//    headerName.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
    
    //joninBtn
    UIButton *joinBtn = [[UIButton alloc] init];
    [contantView addSubview:joinBtn];
    [joinBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(contantView);
        make.trailing.mas_equalTo(contantView).mas_offset(-10 *SCAL);
        make.width.mas_offset(85 *SCAL);
        make.height.mas_offset(25 *SCAL);
    }];
    [joinBtn setBackgroundImage:[UIImage imageNamed:@"group_joinBtn"] forState:UIControlStateNormal];
    [joinBtn setTitle:@"JONIN IN" forState:UIControlStateNormal];
    [joinBtn.titleLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12 *SCAL]];
    [joinBtn.titleLabel setTextAlignment:NSTextAlignmentCenter];
    [joinBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    joinBtn.layer.cornerRadius = 5 *SCAL;
    joinBtn.layer.masksToBounds = YES;
}
-(void)setModel:(JQFYTicketInfo_GroupListModel *)model{
    if (_model == model) {
        return;
    }
    _model = model;
    _groupName.text = _model.group_name?_model.group_name:@"UNINHIBITED";
    _groupCount.text = _model.group_count?_model.group_count:@"100";
    [_iconImg sd_setImageWithURL:[NSURL URLWithString:_model.group_head_path] placeholderImage:[UIImage imageNamed:@"group_iconImg"]];
}
-(void)setAvtivity_Name:(NSString *)avtivity_Name{
    _avtivityLabel.text = avtivity_Name;
}
//cell的高
+(CGFloat)getCellHeight{
    return 85 *SCAL;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
